package com.fusion.lottery.classify.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fusion.lottery.classify.service.ClassifyService;
import com.fusion.lottery.dto.ClassifyDto;
import com.fusion.lottery.mapper.lottery.ClassifyMapper;
import com.fusion.utils.json.Msg;

@Service
public class ClassifyServiceImpl implements ClassifyService{
	
	@Autowired
	private ClassifyMapper classifyMapper;

	@Override
	public Msg list() {
		// TODO Auto-generated method stub
		List<ClassifyDto> list = classifyMapper.list();
		
		List<ClassifyDto> lists = new ArrayList<ClassifyDto>();
		for(ClassifyDto c : list) {
			if(c.getType().equals("0")) {
				List<ClassifyDto> child1 = new ArrayList<ClassifyDto>();
				for(ClassifyDto c1 : list) {
					if(c1.getType().equals("1") && c1.getParentId() == c.getId()) {
						child1.add(c1);
						
						List<ClassifyDto> child2 = new ArrayList<ClassifyDto>();
						c1.setChildren(child2);
						for(ClassifyDto c2 : list) {
							if(c2.getType().equals("2") && c2.getParentId() == c1.getId()) {
								child2.add(c2);
							}
						}
					}
				}
				c.setChildren(child1);
				lists.add(c);
			}
		}
		return new Msg(lists);
	}
	
}
